package com.lsl.data_bus.example.member;

import com.lsl.abstract_factory.example2.App;
import com.lsl.data_bus.example.data.DataType;
import com.lsl.data_bus.example.data.MessageData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * description:
 *
 * @author: liushengli
 * data: 2023/1/12
 */
public class MessageMember implements Member {

    private static final Logger logger = LoggerFactory.getLogger(MessageMember.class);


    private final String name;

    private final List<String> messages = new ArrayList<>();

    public MessageMember(String name) {
        this.name = name;
    }

    @Override
    public void accept(final DataType data) {
        if (data instanceof MessageData) {
            handleEvent((MessageData) data);
        }
    }

    private void handleEvent(MessageData data) {
        logger.info("{} sees message {}", name, data.getMessage());
        messages.add(data.getMessage());
    }

}
